package com.zx.task.manager.mapstruct;

import com.zx.core.enums.StatusEnum;
import com.zx.task.manager.model.TaskTypes;
import com.zx.task.manager.param.TaskTypesParam;
import com.zx.task.manager.vo.TaskTypesVO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

/**
 * <p>
 * description: 任务类型映射 <br>
 * create: 2025-10-13 20:15
 * </p>
 *
 * @author zhou  xun
 */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface TaskTypesMapStructMapper {
    TaskTypesMapStructMapper INSTANCE = Mappers.getMapper(TaskTypesMapStructMapper.class);

    /**
     * 将TaskTypesParam转换为TaskTypes实体
     *
     * @param taskTypesParam 任务类型参数
     * @return TaskTypes实体
     */
    TaskTypes taskTypesParamToTaskTypes(TaskTypesParam taskTypesParam);

    /**
     * 将TaskTypes实体转换为TaskTypesVO视图对象
     *
     * @param taskTypes 任务类型实体
     * @return TaskTypesVO视图对象
     */
    TaskTypesVO taskTypesToTaskTypesVO(TaskTypes taskTypes);

    /**
     * 在映射完成后，设置描述性字段
     *
     * @param taskTypes   任务类型实体
     * @param taskTypesVO 任务类型VO
     */
    @AfterMapping
    default void setDescriptions(TaskTypes taskTypes, @MappingTarget TaskTypesVO taskTypesVO) {
        // 设置状态描述
        StatusEnum statusEnum = StatusEnum.getEnumByCode(taskTypes.getStatus());
        if (statusEnum != null) {
            taskTypesVO.setStatusDesc(statusEnum.getDesc());
        }
    }
}